/** 重新申请 */
function apply(id, tranType) {
    $.operate.post({
        url: ctx + "repeatApply",
        data: {id: id, tranType: tranType},
        fun: function () {
            location.href = ctx + "index";
        }
    })
}

/** 插销申请 */
function cancelApply(id, tranType) {
    $.operate.post({
        url: ctx + "cancel/apply",
        data: {id: id, tranType: tranType},
        fun: function () {
            location.href = ctx + "index";
        }
    })
}

/** 插销接收 */
function cancelRec(id, tranType) {
    $.operate.post({
        url: ctx + "cancel/rec",
        data: {id: id, tranType: tranType},
        fun: function () {
            location.href = ctx + "index";
        }
    })
}

/** 插销质检 */
function cancelCheck(id, tranType) {
    $.operate.post({
        url: ctx + "cancel/check",
        data: {id: id, tranType: tranType},
        fun: function () {
            location.href = ctx + "index";
        }
    })
}

function del(id, tranType) {
    $.operate.post({
        url: ctx + "delApply",
        data: {id: id, tranType: tranType},
        fun: function () {
            location.href = ctx + "index";
        }
    })
}

$(function () {

    $("#btn-updatePassword").click(function () {
        if ($("#password").val() && $("#password2").val()
            && $("#password").val() == $("#password2").val()) {
            $.operate.post({
                url: ctx + "upp",
                data: {pwd: $("#password").val()},
                fun: function () {
                    $.closePopup();
                    $.box.toptip_s();
                }
            })
        } else {
            $.box.toptip_w('两次密码输入不一致');
        }
    });

    /*$("#ac").on('change', function () {
        $("#city").val($(this).val());
        if ($(this).val()) {
            $("#city-div").hide();
        } else {
            $("#city-div").show();
        }
    });*/

    // var minDate = $("#yearMonth").val();

    /** ------------------------报备------------------------ */
    // 报备开始时间配置
    /*$(".report-date").calendar({
      dateFormat: "yyyy-mm-dd",
      minDate: minDate,
      onClose: function () {
        $(this.input).trigger('blur');
        var sd = $(this.input).parents("form").find("input[name='startTime']").val();
        var ed = $(this.input).parents("form").find("input[name='endTime']").val();
        if (sd && ed) {
          $(this.input).parents("form").find("input[name='reportDays']").val($.common.diffDay(sd, ed));
        } else {
          $(this.input).parents("form").find("input[name='reportDays']").val('');
        }
      }
    });*/

    // 小时假时间配置
    /*$(".report-dateTime").datetimePicker({
      title: '选择时间',
      min: minDate,
      onClose: function () {
        /!*$(this.input).trigger('blur');
        var sd = $(this.input).parents("form").find("input[name='startTime']").val();
        var ed = $(this.input).parents("form").find("input[name='endTime']").val();
        if (sd && ed) {
          $(this.input).parents("form").find("input[name='reportDays']").val($.common.diffHourExtend(sd, ed));
        } else {
          $(this.input).parents("form").find("input[name='reportDays']").val('');
        }*!/
      }
    });*/

    // 报备原因选择
    /*  $(".report-reason").change(function () {
        $(this).parents("form").find("textarea[name='reason']").text($(this).val()).trigger('blur');
      });*/

    // 报备提交
    /*$(".btn-report").click(function () {
      var type = $(this).attr("id").replace('btn-', '');
      var reportForm = $("#" + type + "-form");
      if (type ==="add" && $("#addSalary").val() === '0') {
        $.box.toptip_w('你没有加班工资，不能报备加班，请联系管理员');
        return;
      }
      if ((type === 'bear' || type === 'check') && $("#sex").val() === '男') {
        $.box.toptip_w('你的性别不符合要求， 无法报备');
        return;
      }
      /!*if (type === 'hour' && $.common.diffDay(reportForm.find("input[name='startTime']").val(), reportForm.find("input[name='endTime']").val()) >= 2) {
        $.box.toptip_w('小时假不能跨天报备');
        return;
      }*!/
        if (type === 'hour' && reportForm.find("input[name='reportDays']").val() > 24) {
            $.box.toptip_w('半天假报备时间不得超过24小时');
            return;
        }
      if (type !== 'hour' && (!reportForm.find("input[name='reportDays']").val() || reportForm.find("input[name='reportDays']").val() < 1)) {
        $.box.toptip_w('报备时间选择错误');
        return;
      }
      $.operate.uploadPost(ctx + "report",reportForm,function () {
        reportForm[0].reset();
        reportForm.find("textarea[name='reason']").text("");
        $.closePopup();
      }, true, "内容填写不完整", true);
    });*/


    /***************出勤统计**********************/

    /*$("#tab2-dateQuery").picker({
      title: "请选择查询日期",
      value: $("#tab2-dateQuery").val().split('-'),
      cols:[
        {
          textAlign: 'left',
          values: (function () {//年份
            for(var years = [], k = 2019; k <= new Date().getFullYear(); k++) {
              years.push(k);
            }
            return years;
          })()
        },
        {
          divider: true,  // 这是一个分隔符
          content: '-'
        },
        {
          textAlign: 'right',
          values:(function () {//月份
            return "01 02 03 04 05 06 07 08 09 10 11 12".split(" ");
          })()
        }
      ],
      formatValue: function (p) {
        return p.cols.map(function (col) {
          return col.value || col.content;
        }).join('');
      },
      onClose:function (e) {
        getAttendance();
      }
    });*/

    // 获取页面数据
    /*getAttendance();*/

    /***************工资**********************/

    /*$("#tab3-dateQuery").picker({
      title: "请选择查询日期",
      value: $("#tab3-dateQuery").val().split('-'),
      cols:[
        {
          textAlign: 'left',
          values: (function () {//年份
            for(var years = [], k = 2019; k <= new Date().getFullYear(); k++) {
              years.push(k);
            }
            return years;
          })()
        },
        {
          divider: true,  // 这是一个分隔符
          content: '-'
        },
        {
          textAlign: 'right',
          values:(function () {//月份
            return "01 02 03 04 05 06 07 08 09 10 11 12".split(" ");
          })()
        }
      ],
      formatValue: function (p) {
        return p.cols.map(function (col) {
          return col.value || col.content;
        }).join('');
      },
      onClose:function (e) {
        getSalary();
      }
    });*/

    // 获取工资明细
    // getSalary();

    // 确认工资
    /*$("#btn-sureSalary").click(function () {
      $.operate.post(ctx + "salary/sure", {said: $("#said").val()}, function () {
        getSalary()
      }, true)
    });

    $("#btn-errorSalary").click(function () {
        $.operate.post(ctx + "/status", {id: $("#said").val()}, function (result) {
            if (result > 1) {
                $.modal.warning("工资正在调整中，无法完成申请，请联系管理员!!!");
            } else {
                if($("#reason").val()==''){
                    $.box.toptip_w('工资申请重新核实需要填写原因!!!');
                    return;
                }
                $.operate.post(ctx + "salary/change", {said: $("#said").val(), reason: $("#reason").val()}, function () {
                    getSalary()
                }, true)
            }
        })
    });*/

    /***************审核**********************/
    // 搜索
    /*$("#search").click(function () {
        getCheck();
    });*/

    // 获取审核列表数据
    // getCheck();

    // 驳回报备
    /*$("#btn-check-reject").click(function () {
      $.operate.uploadPost(ctx + "check/reject",$("#check-reject-form"),function () {
        $("#check-reject-id").val('');
        $("#check-reject-form textarea").text('');
        $.closePopup();
        getCheck();
      }, true, "", true);
    });*/

    // 一键审核
    /*$("#btn-check-all").click(function () {
      $.operate.post(ctx + "check/all", {"checkCode":$("#empCode").val()}, function () {
        getCheck();
      }, true);
    });*/

});

// 获取审核列表数据
/*function getCheck() {
  $("#check-list").empty();

  // 获取审核列表数据
  $.operate.post(ctx + "check",{
      nameQuery: $("#nameQuery").val(),
      reportTypeQuery: $("#reportTypeQuery").val(),
      statusQuery: $("#statusQuery").val(),
      checkManQuery:$("#empCode").val()},function (result) {
    if (result.data) {
      $.each(result.data, function (index, value) {
        $("#check-list").append(createCheckElement(value));
      });
    }
  }, false);
}*/


// 创建审核列表元素
/*function createCheckElement(data) {
  var statusString = ['撤销','提交待审','审阅待批','审批通过','驳回'];
  var outCheckStr = ["（无补助）", "（有补助）", ""];
  var root = $("<div></div>").addClass("weui-form-preview");
  var row1 = $("<div></div>").addClass("weui-form-preview__hd")
      .append($("<div></div>").addClass("weui-form-preview__item")
          .append($("<label></label>").addClass("weui-form-preview__label").text("状态"))
          .append($("<span></span>").addClass("weui-form-preview__item").text(statusString[data.status])))
      .append($("<div></div>").addClass("weui-form-preview__item")
          .append($("<label></label>").addClass("weui-form-preview__label").text("报备人"))
          .append($("<span></span>").addClass("weui-form-preview__item").text(data.empName + "     " + data.empCode)))
      .append($("<div></div>").addClass("weui-form-preview__item")
          .append($("<label></label>").addClass("weui-form-preview__label").text("岗位"))
          .append($("<span></span>").addClass("weui-form-preview__item").text(data.postName)))
      .append($("<div></div>").addClass("weui-form-preview__item")
          .append($("<label></label>").addClass("weui-form-preview__label").text("报备类型"))
          .append($("<span></span>").addClass("weui-form-preview__item").text(data.reportTypeName + " " + outCheckStr[data.outCheckStatus])))
      .append($("<div></div>").addClass("weui-form-preview__item")
          .append($("<label></label>").addClass("weui-form-preview__label").text("开始时间"))
          .append($("<span></span>").addClass("weui-form-preview__item").text(data.realStartTime + " " + new Date(data.realStartTime).week())))
      .append($("<div></div>").addClass("weui-form-preview__item")
          .append($("<label></label>").addClass("weui-form-preview__label").text("结束时间"))
          .append($("<span></span>").addClass("weui-form-preview__item").text(data.realEndTime + " " + new Date(data.realEndTime).week())))
      .append($("<div></div>").addClass("weui-form-preview__item")
          .append($("<label></label>").addClass("weui-form-preview__label").text("报备天数"))
          .append($("<span></span>").addClass("weui-form-preview__item").text(data.reportDays + "天")));

  var row2 = $("<div></div>").addClass("weui-form-preview__ft");
  if (data.status == 1 && data.accountStatus == 0) {
    row2.append($("<a href='javascript:void(0);' onclick='getSure(" + data.id + ")'></a>").addClass("weui-form-preview__btn weui-form-preview__btn_primary").text("批准"))
        .append($("<a href='javascript:void(0);' onclick='getReject(" + data.id + ")'></a>").addClass("weui-form-preview__btn weui-form-preview__btn_primary").text("驳回"));
  }
  if (data.status == 3 && data.accountStatus == 0) {
    row2.append($("<a href='javascript:void(0);'  onclick='getReject(" + data.id + ")'></a>").addClass("weui-form-preview__btn weui-form-preview__btn_primary").text("驳回"));
  }
  root.append(row1).append(row2);
  return root;
}*/

//审核通过
/*function getSure(id) {
  $.operate.post(ctx + "check/sure", {"id": id,"checkCode":$("#empCode").val()}, function () {
    getCheck();
  }, true)
}*/

// 驳回事件
/*function getReject(id) {
  $("#check-reject").popup();
  $("#check-reject-id").val(id);
}*/

// var s_s = 0;

// 获取工资明细
/*function getSalary() {
  $.operate.post(ctx + "salary",{empCode:$("#empCode").val(),yearMonth: $("#tab3-dateQuery").val()},function (result) {
    if (result) {
      // 查询到工资的情况
      $("#salary-1").text(result.mustWage);
      $("#said").val(result.id);
      showSalary();

      if (result.maStatus) {
        // 未月结情况
        $.operate.post(ctx + "salary/checkFlag", {said: result.id}, function (result2) {
          s_s = result.checkFlag;
          if (result2) {
            if (!result2.status) {
              $("#check-salary").show();
            } else {
              $("#check-salary").hide();
            }

            if (result2.status == 1) {
              $("#f1").text("申请核实");
            }
            if (result2.status == 2) {
              $("#f1").text("已经确认");
            }

            if (result.status == 1 && (result2.checkFlag == 5 || result2.checkFlag == 6)) {
              //不予调整
              $("#f2").text('不予调整');
            }
            else if (result.status == 1 && (result2.checkFlag == 2 || result2.checkFlag == 3)) {
              //调整未审批
              $("#f2").text("未 审 批");
            }
            else if (result.status == 1 && result2.checkFlag == 4) {
              //审批通过，调整工资
              $("#f2").text("已 调 整");
            }
          } else {
            $("#f1").text("");
          }
        });

      } else {
        // 已月结情况， 隐藏申请框， 显示进度框， 内容显示为已经确认
        $("#check-salary").hide();
        $("#f1").text("已经确认");
      }
    } else {
      // 没查询到工资的情况
      $("#salary-1").text('查无数据');
      $("#said").val('');
      hideSalary();
    }
  }, false);
}*/

/*function hideSalary() {
  $("#check-salary").hide();
  $("#schedule-salary").hide();
}

function showSalary() {
  $("#check-salary").show();
  $("#schedule-salary").show();
}*/

// 获取出勤数据
/*function getAttendance() {
  $("#attendance-list").empty();
  // 统计信息
  $.operate.post(ctx + "attendance/count",{nameQuery:$("#empCode").val(),yearMonthQuery: $("#tab2-dateQuery").val()},function (result) {
    if (result) {
      $("#att-1").text(result.workDays);
      $("#att-2").text(result.salaryDays + result.halfSalaryDays + result.noneSalaryDays);
      $("#att-3").text(result.noneWorkDays);
      $("#att-4").text(result.outHaveDays + result.outNoneDays);
      $("#att-5").text(result.leaveDays + result.hourDays + result.sickDays + result.maternityDays + result.marriageDays);
      $("#att-6").text(result.overtimeDays);
      $("#att-7").text(result.lateDays);
      $("#att-8").text(result.earlyDays);
      $("#att-9").text(result.notOnDays);
      $("#att-10").text(result.notOffDays);
    } else {
      $("#att-1").text('');
      $("#att-2").text('');
      $("#att-3").text('');
      $("#att-4").text('');
      $("#att-5").text('');
      $("#att-6").text('');
      $("#att-7").text('');
      $("#att-8").text('');
      $("#att-9").text('');
      $("#att-10").text('');
    }
  }, false);
  // 详细信息
  $.operate.post(ctx + "attendance/info",{nameQuery:$("#empCode").val(),yearMonthQuery: $("#tab2-dateQuery").val()},function (result) {
    if (result.data) {
      $.each(result.data, function (index, value) {
        $("#attendance-list").append(createAttendanceElement(value));
      });
    }
  }, false);
}*/

// 构建出勤详细列表元素
/*function createAttendanceElement(data) {
  var uri;
  if (data.reportTypeName === '公休') {
    uri = local + "img/t10.jpg";
  } else if(data.reportTypeName === '出勤') {
    uri = local + "img/t1.jpg";
  } else if(data.reportTypeName === '事假') {
    uri = local + "img/t4.jpg";
  } else if(data.reportTypeName === '产假') {
    uri = local + "img/t6.jpg";
  } else if(data.reportTypeName === '加班') {
    uri = local + "img/t2.jpg";
  } else if(data.reportTypeName === '病假') {
    uri = local + "img/t5.jpg";
  } else if(data.reportTypeName === '出差') {
    uri = local + "img/t3.jpg";
  } else if(data.reportTypeName === '婚假') {
    uri = local + "img/t9.jpg";
  } else if(data.reportTypeName === '丧假') {
    uri = local + "img/t8.jpg";
  } else if(data.reportTypeName === '小时假') {
    uri = local + "img/t11.jpg";
  } else if(data.reportTypeName === '产检假') {
    uri = local + "img/t7.jpg";
  }
  var root = $("<a href='javascript:void(0);'></a>").addClass("weui-media-box weui-media-box_appmsg");
  var row1 = $("<div></div>").addClass("weui-media-box__hd")
      .append($("<img src='" + uri + "' alt=''>").addClass("weui-media-box__thumb"));

  var row2 = $("<div></div>").addClass("weui-media-box__bd")
      .append($("<h4></h4>").addClass("weui-media-box__title")
          .append(data.attendDate)
          .append($("<span></span>").addClass("weui-media-box__title-after").css("color","#2a6ef0").text(new Date(data.attendDate).week())))
      .append($("<p></p>").addClass("weui-media-box__desc").text("上班时间 " + (data.onTime ? data.onTime : '') + " 下班时间 " + (data.offTime ? data.offTime : '')));
  root.append(row1).append(row2);
  return root;
}*/

